<?php

namespace App\Admin\Controllers;

// use Encore\Admin\Auth\Permission;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\ModelForm;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use App\Models\Banner;

class BannerController extends Controller
{
    use ModelForm;
    public function index()
    {
        return Admin::content(function (Content $content) {
            $content->header('轮播图');
            $content->description('管理');
            $content->body($this->grid());
        });
    }

    public function edit($id)
    {
        return Admin::content(function (Content $content) use ($id) {
            $content->header('轮播');
            $content->description('编辑');

            $content->body($this->form()->edit($id));
        });
    }

    public function create()
    {
        return Admin::content(function (Content $content) {
            $content->header('轮播');
            $content->description('创建');

            $content->body($this->form());
        });
    }

    protected function grid()
    {
        return Admin::grid(Banner::class, function (Grid $grid) {
            // $grid->position_tags('轮播图序号');
            $grid->id('序号');
            $grid->name('轮播图名称');
            $grid->img_url('轮播图路径')->image();
            // $grid->go_url('跳转');
            $grid->disableFilter();
            $grid->disableExport();
            // $grid->disableCreateButton();
            // $grid->disablePagination();
            $grid->disableFilter();
            $grid->paginate(4);
            $grid->perPages([4]);
            $grid->disableRowSelector();
            $grid->disableCreateButton();
            // $grid->disableActions();
            $grid->actions(function ($actions) {
                // $actions->disableDelete();
                $actions->disableDelete();
            });
        });
    }

    protected function form()
    {
        return Admin::form(Banner::class, function (Form $form) {
            // $form->text('position_tags', '轮播图位置');
            $form->text('name', '轮播图名称');
            $form->image('img_url', '轮播图');
            // $form->display('id', 'ID')
            // $form->url('go_url', '跳转链接');
        });
    }
}
